package com.qingcheng.service.impl;

import com.alibaba.dubbo.config.annotation.Service;
import com.qingcheng.dao.CategoryReportMapper;
import com.qingcheng.pojo.order.CategoryReport;
import com.qingcheng.service.order.CategoryReportService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;


import java.time.LocalDate;
import java.util.List;
import java.util.Map;

/**
 * @author yangjun
 * 2019/7/2
 * 23:42
 */
@Service(interfaceClass = CategoryReportService.class)
public class CategoryReportServiceImpl implements CategoryReportService {
    @Autowired
    private CategoryReportMapper categoryReportMapper;

    /**
     * 查询前一天数据
     * @param date
     * @return
     */
    @Override
    public List<CategoryReport> categoryReport(LocalDate date) {
     return categoryReportMapper.categoryReport(date);

    }

    /**
     * 定时统计数据
     */
    @Override
    @Transactional
    public void createData() {
        LocalDate localDate = LocalDate.now().minusDays(1);//得到昨天的日期
        //得到昨天的数据List集合
        List<CategoryReport> categoryReports = categoryReportMapper.categoryReport(localDate);
        //遍历集合 ,将数据添加进数据库
        for (CategoryReport categoryReport : categoryReports) {
            categoryReportMapper.insert(categoryReport);
        }
    }

    /**
     * 一级类目统计
     * @param date1
     * @param date2
     * @return
     */
    @Override
    public List<Map> category1Count(String date1, String date2) {
        return categoryReportMapper.category1Count(date1,date2);
    }
}
